package com.lianqi.emcpframework.ddd.gencode.application.repository;

import java.util.stream.Collectors;

import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;

import com.lianqi.emcpframework.ddd.gencode.application.GenApplicationIgnore;

public final class RepositoryBasedMethodMetaParser {

    public RepositoryBasedMethodMeta parse(TypeElement modelType, TypeElement modelVoType,
        TypeElement repositoryElement) {
        RepositoryBasedMethodMeta methodMeta = new RepositoryBasedMethodMeta(modelType, modelVoType);
        ElementFilter.methodsIn(repositoryElement.getEnclosedElements()).stream()
            .filter(executableElement -> executableElement.getAnnotation(GenApplicationIgnore.class) == null)
            // .filter(executableElement -> executableElement.getAnnotation(QueryMethod.class) != null)
            .collect(Collectors.toSet()).forEach(executableElement -> methodMeta.addQueryMethod(executableElement));

        return methodMeta;
    }

}
